import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

// const use模块名Store = defineStore('模块名', { 配置项 })
/*
export const useCounterStore = defineStore('counter', {
  state: () => ({ // 定义state
    count: 0,
    msg: '皮雅尼'
  }),
  actions: { // mutations 和 actions 综合体
    increment() {
      this.count++
    },
    asyncIncrement() {
      setTimeout(() => {
        this.count += 10
      }, 3000)
    }
  }
})*/



export const useCounterStore = defineStore('counter', () => {
  const msg = ref('Hello Pinia!')
  const reversedFun = () => {
    msg.value = '你好皮雅尼！'
  }

  const count = ref(1010)

  const increment = () => {
    count.value++
    console.log(count.value)
  }

  const asyncIncrement = () => {
    setTimeout(() => {
      count.value = count.value * 11
    }, 3000)
  }

  return { count, increment, asyncIncrement, msg, reversedFun }
})
















/*
export const useCounterStore = defineStore('counter', () => {
  const count = ref(0)
  const doubleCount = computed(() => count.value * 2)
  function increment() {
    count.value++
  }

  return { count, doubleCount, increment }
})*/
